package com.mybatisflex.demo.listener;

import com.mybatisflex.annotation.InsertListener;
import com.mybatisflex.annotation.UpdateListener;
import com.mybatisflex.demo.entity.Card;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @author 王帅
 * @since 2023-07-19
 */
public class CardListener implements InsertListener, UpdateListener {

    @Override
    public void onInsert(Object entity) {
        Card card = (Card) entity;
        card.setIdNumber(UUID.randomUUID().toString());
        card.setCreateTime(LocalDateTime.now());
    }

    @Override
    public void onUpdate(Object entity) {
        Card card = (Card) entity;
        card.setUpdateTime(LocalDateTime.now());
    }

}